package com.glsc.ngateway.platform.utils.file;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * excel文件管理器
 */
@Slf4j
@Component
public class ExcelFileManager {

    /**
     * 创建Excel返回字节流
     * @param datas 数据
     * @param excelNameEn 模板
     * @return 字节流
     */
    public byte[] buildExcelFileByte(List<List<String>> datas, ExcelNameEnum excelNameEn) {
        ExcelUtil eu = new ExcelUtil();
        eu.buildParamter(excelNameEn);
        return eu.buildExcelFileByte(datas, excelNameEn.getFileName(), 0);
    }

    /**
     * 创建Excel返回字节流
     * @param datas 数据
     * @param excelNameEn 模板
     * @return 字节流
     */
    public Workbook buildExcelWorkBook(List<List<String>> datas, ExcelNameEnum excelNameEn) {
        ExcelUtil eu = new ExcelUtil();
        eu.buildParamter(excelNameEn);
        return eu.buildExcelWorkBook(datas, excelNameEn.getFileName(), 0);
    }

    public Workbook addExcelData(Workbook wb, List<List<String>> buildDatas) {
        ExcelUtil eu = new ExcelUtil();
        return eu.addExcelData(wb, buildDatas);
    }

    public byte[] convertToBytes(Workbook wb) {
        ExcelUtil eu = new ExcelUtil();
        return eu.convertToBytes(wb);
    }
}
